package com.opbx.callCenter.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.opbx.common.annotation.Log;
import com.opbx.common.core.controller.BaseController;
import com.opbx.common.core.domain.AjaxResult;
import com.opbx.common.enums.BusinessType;
import com.opbx.callCenter.domain.CallCenterExtension;
import com.opbx.callCenter.service.ICallCenterExtensionService;
import com.opbx.common.utils.poi.ExcelUtil;
import com.opbx.common.core.page.TableDataInfo;

/**
 * 分机设置Controller
 * 
 * @author opbx
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/callCenter/CallCenterExtension")
public class CallCenterExtensionController extends BaseController
{
    @Autowired
    private ICallCenterExtensionService callCenterExtensionService;

    /**
     * 查询分机设置列表
     */
    @PreAuthorize("@ss.hasPermi('callCenter:CallCenterExtension:list')")
    @GetMapping("/list")
    public TableDataInfo list(CallCenterExtension callCenterExtension)
    {
        startPage();
        List<CallCenterExtension> list = callCenterExtensionService.selectCallCenterExtensionList(callCenterExtension);
        return getDataTable(list);
    }

    /**
     * 导出分机设置列表
     */
    @PreAuthorize("@ss.hasPermi('callCenter:CallCenterExtension:export')")
    @Log(title = "分机设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CallCenterExtension callCenterExtension)
    {
        List<CallCenterExtension> list = callCenterExtensionService.selectCallCenterExtensionList(callCenterExtension);
        ExcelUtil<CallCenterExtension> util = new ExcelUtil<CallCenterExtension>(CallCenterExtension.class);
        util.exportExcel(response, list, "分机设置数据");
    }

    /**
     * 获取分机设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('callCenter:CallCenterExtension:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(callCenterExtensionService.selectCallCenterExtensionById(id));
    }

    /**
     * 新增分机设置
     */
    @PreAuthorize("@ss.hasPermi('callCenter:CallCenterExtension:add')")
    @Log(title = "分机设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CallCenterExtension callCenterExtension)
    {
        return toAjax(callCenterExtensionService.insertCallCenterExtension(callCenterExtension));
    }

    /**
     * 修改分机设置
     */
    @PreAuthorize("@ss.hasPermi('callCenter:CallCenterExtension:edit')")
    @Log(title = "分机设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CallCenterExtension callCenterExtension)
    {
        return toAjax(callCenterExtensionService.updateCallCenterExtension(callCenterExtension));
    }

    /**
     * 删除分机设置
     */
    @PreAuthorize("@ss.hasPermi('callCenter:CallCenterExtension:remove')")
    @Log(title = "分机设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(callCenterExtensionService.deleteCallCenterExtensionByIds(ids));
    }

    /**
     * 改变分机状态
     * @param callCenterExtension
     * @return
     */
    @PostMapping("/changeExtensionStatus")
    public AjaxResult changeExtensionStatus(@RequestBody CallCenterExtension callCenterExtension){
        int i = callCenterExtensionService.changeExtensionStatus(callCenterExtension);
        return toAjax(i);
    }
}
